USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Insert]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Insert record into table [dbo].[MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Insert]
	/*@MeasureUnit_RowNumber int =Null OUTPUT , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@MeasureUnit_Notes varchar(max) =Null  , 
	@MeasureUnit_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[MeasureUnits](/*[MeasureUnit_ID], [MeasureUnit_Code], [MeasureUnit_NameAr], [MeasureUnit_NameEn], [MeasureUnit_Notes], [MeasureUnit_Search]*/)
	VALUES     (/*@MeasureUnit_ID, @MeasureUnit_Code, @MeasureUnit_NameAr, @MeasureUnit_NameEn, @MeasureUnit_Notes, @MeasureUnit_Search*/)

	/*SELECT @MeasureUnit_RowNumber = [MeasureUnit_RowNumber]
    FROM [dbo].[MeasureUnits]
    WHERE  ( [MeasureUnit_ID] =@MeasureUnit_ID )
	AND  ( [MeasureUnit_Code] =@MeasureUnit_Code )
	AND  ( [MeasureUnit_NameAr] =@MeasureUnit_NameAr )
	AND  ( [MeasureUnit_NameEn] =@MeasureUnit_NameEn )
	AND  ( [MeasureUnit_Notes] =@MeasureUnit_Notes )
	AND  ( [MeasureUnit_Search] =@MeasureUnit_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-update]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Update record in table [dbo].[MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-update]
	/*@MeasureUnit_RowNumber int =Null OUTPUT , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@MeasureUnit_Notes varchar(max) =Null  , 
	@MeasureUnit_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[MeasureUnits] SET 
		/*[MeasureUnit_ID] =@MeasureUnit_ID, 
		[MeasureUnit_Code] =@MeasureUnit_Code, 
		[MeasureUnit_NameAr] =@MeasureUnit_NameAr, 
		[MeasureUnit_NameEn] =@MeasureUnit_NameEn, 
		[MeasureUnit_Notes] =@MeasureUnit_Notes, 
		[MeasureUnit_Search] =@MeasureUnit_Search*/
		/*WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
	/**/

	/*SELECT @MeasureUnit_RowNumber = [MeasureUnit_RowNumber]
    FROM [dbo].[MeasureUnits]
	WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Insert-Update]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	Insert OR Update record into table [dbo].[MeasureUnits]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Insert-Update]
	/*@MeasureUnit_RowNumber int =Null OUTPUT , 
	@MeasureUnit_ID uniqueidentifier =Null  , 
	@MeasureUnit_Code varchar(50) =Null  , 
	@MeasureUnit_NameAr varchar(300) =Null  , 
	@MeasureUnit_NameEn varchar(300) =Null  , 
	@MeasureUnit_Notes varchar(max) =Null  , 
	@MeasureUnit_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[MeasureUnits] 
					/*WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[MeasureUnits](/*[MeasureUnit_ID], [MeasureUnit_Code], [MeasureUnit_NameAr], [MeasureUnit_NameEn], [MeasureUnit_Notes], [MeasureUnit_Search]*/)
		VALUES     (/*@MeasureUnit_ID, @MeasureUnit_Code, @MeasureUnit_NameAr, @MeasureUnit_NameEn, @MeasureUnit_Notes, @MeasureUnit_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[MeasureUnits] SET 
			/*[MeasureUnit_ID] =@MeasureUnit_ID, 
			[MeasureUnit_Code] =@MeasureUnit_Code, 
			[MeasureUnit_NameAr] =@MeasureUnit_NameAr, 
			[MeasureUnit_NameEn] =@MeasureUnit_NameEn, 
			[MeasureUnit_Notes] =@MeasureUnit_Notes, 
			[MeasureUnit_Search] =@MeasureUnit_Search*/
			/*WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @MeasureUnit_RowNumber = [MeasureUnit_RowNumber]
    FROM [dbo].[MeasureUnits]
	WHERE ([MeasureUnit_ID] = @MeasureUnit_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Delete]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	delete records from table [dbo].[MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Delete]
	/*@MeasureUnit_RowNumber int =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@MeasureUnit_Code varchar(50) =null  , 
	@MeasureUnit_NameAr varchar(300) =null  , 
	@MeasureUnit_NameEn varchar(300) =null  , 
	@MeasureUnit_Notes varchar(max) =null  , 
	@MeasureUnit_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[MeasureUnits]
	WHERE /*( [MeasureUnit_RowNumber] = ISNULL(@MeasureUnit_RowNumber, [MeasureUnit_RowNumber]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [MeasureUnit_Code] like ISNULL(@MeasureUnit_Code, [MeasureUnit_Code]) )
	AND ( [MeasureUnit_NameAr] like ISNULL(@MeasureUnit_NameAr, [MeasureUnit_NameAr]) )
	AND ( [MeasureUnit_NameEn] like ISNULL(@MeasureUnit_NameEn, [MeasureUnit_NameEn]) )
	AND ( [MeasureUnit_Notes] like ISNULL(@MeasureUnit_Notes, [MeasureUnit_Notes]) )
	AND ( [MeasureUnit_Search] like ISNULL(@MeasureUnit_Search, [MeasureUnit_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[MeasureUnits-Select]    Script Date: [[20120714223934]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223934]]
-- Description:	select records from table [dbo].[MeasureUnits] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[MeasureUnits-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[MeasureUnits-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[MeasureUnits-Select]
	/*@MeasureUnit_RowNumber int =null  , 
	@MeasureUnit_ID uniqueidentifier =null  , 
	@MeasureUnit_Code varchar(50) =null  , 
	@MeasureUnit_NameAr varchar(300) =null  , 
	@MeasureUnit_NameEn varchar(300) =null  , 
	@MeasureUnit_Notes varchar(max) =null  , 
	@MeasureUnit_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[MeasureUnits]
	WHERE /*( [MeasureUnit_RowNumber] = ISNULL(@MeasureUnit_RowNumber, [MeasureUnit_RowNumber]) )
	AND ( [MeasureUnit_ID] = ISNULL(@MeasureUnit_ID, [MeasureUnit_ID]) )
	AND ( [MeasureUnit_Code] like ISNULL(@MeasureUnit_Code, [MeasureUnit_Code]) )
	AND ( [MeasureUnit_NameAr] like ISNULL(@MeasureUnit_NameAr, [MeasureUnit_NameAr]) )
	AND ( [MeasureUnit_NameEn] like ISNULL(@MeasureUnit_NameEn, [MeasureUnit_NameEn]) )
	AND ( [MeasureUnit_Notes] like ISNULL(@MeasureUnit_Notes, [MeasureUnit_Notes]) )
	AND ( [MeasureUnit_Search] like ISNULL(@MeasureUnit_Search, [MeasureUnit_Search]) )*/
END
GO
-- =============================================
